<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:output method="html"/>
	<xsl:template match="/">
		<xsl:apply-templates select="*"/>
	</xsl:template>
	<xsl:variable name="chapterId" select="chapter/@chapId"/>
	<xsl:param name="caleComment"/>
	<xsl:variable name="comentarii" select="document($caleComment)/chapterComments"/>
	<xsl:template match="title">
		<xsl:variable name="chapterId" select="parent::chapter/@chapId"/>
		<div>
			<p align="center">
				<xsl:value-of select="text()"/>
			</p>
			<input type="hidden" value="{$chapterId}" id="curentChapterId"/>
		</div>
	</xsl:template>
	<xsl:template match="paragraph">
		<xsl:variable name="paraId" select="@paraId"/>
		<div class="paragraph" id="{$paraId}" onclick="editPara('{$paraId}','{$paraId}p');">
			<p id="{$paraId}p">
				<xsl:value-of select="text()"/>
			</p>
		</div>
		<xsl:if test="$comentarii/chapterComment[commentElementId=$paraId]">
			<div class="commentHelder">
				<span class="commentAnnouncement">++Comentarii</span>
				<br/>
				<div class="comment">
					<div class="commentHeader" align="left">
						<b>Comentarii...</b>
					</div>
					<xsl:for-each select="$comentarii/chapterComment[commentElementId=$paraId]">
						<div class="commentBody">
							<xsl:value-of select="commentAuthor"/>, <xsl:value-of select="commentDate"/>
							<br/>
							<xsl:value-of select="commentContent"/>
						</div>
					</xsl:for-each>
				</div>
			</div>
			<br/>
		</xsl:if>
	</xsl:template>
	<xsl:template match="note">
		<xsl:variable name="noteId" select="@noteId"/>
		<div class="note" id="{$noteId}" onclick="editPara('{$noteId}','{$noteId}p')">
			<p align="left">Note:</p>
			<p id="{$noteId}p">
				<xsl:value-of select="text()"/>
			</p>
		</div>
	</xsl:template>
	<xsl:template match="quote">
		<xsl:variable name="quoteId" select="@quoteId"/>
		<div class="quote" id="{$quoteId}" onclick="editPara('{$quoteId}','{$quoteId}p')">
			<p id="{$quoteId}p">
				<xsl:text>" </xsl:text>
				<xsl:value-of select="text()"/>
				<xsl:text> "</xsl:text>
			</p>
		</div>
	</xsl:template>
	<xsl:template match="image">
		<xsl:variable name="imgPath" select="imgSrc"/>
		<xsl:variable name="imgMIME" select="imgMIME"/>
		<div class="image">
			<img src="{$imgPath}.{$imgMIME}"/>
			<p align="center">
				<xsl:value-of select="imgCaption/text()"/>
			</p>
		</div>
	</xsl:template>
	<xsl:template match="table">
		<xsl:variable name="tableId" select="@tbId"/>
		<div class="deleteTable" id="delTab_{$tableId}" onmouseover="this.className='deleteTableHover'; this.innerHTML='Delete table'" onmouseout="this.className='deleteTable'; this.innerHTML='X'" onclick="deleteTable('{$tableId}')">X</div>
		<div class="table" id="{$tableId}">
			<table class="editorTable" align="center">
				<caption align="bottom" class="editorTable">
					<p onclick="changeTableCaption('{$tableId}');">
						<xsl:value-of select="tableCaption"/>
					</p>
				</caption>
				<thead>
					<tr id="{$tableId}_0">
						<xsl:for-each select="tableHeader/tableRow/tableColumn">
							<td class="editorTableHeader">
								<xsl:value-of select="text()"/>
							</td>
						</xsl:for-each>
						<td class="editorTableHeader">
							<div class="editRowMenu" onclick="editTableRow('{$tableId}','0');" onmouseover="this.className='editRowMenuHover'" onmouseout="this.className='editRowMenu'">Edit</div>
							<div class="editRowMenu" onclick="editTableAddRow('{$tableId}');" onmouseover="this.className='editRowMenuHover'" onmouseout="this.className='editRowMenu'">Add row</div>
						</td>
					</tr>
				</thead>
				<tbody>
					<xsl:for-each select="tableRow">
						<xsl:variable name="rowInd" select="@rowIndex"/>
						<tr id="{$tableId}_{$rowInd}" onmouseover="this.className='editorTableHighlight'" onmouseout="this.className='editorTableNormal'">
							<xsl:for-each select="tableColumn">
								<td>
									<xsl:value-of select="text()"/>
								</td>
							</xsl:for-each>
							<td>
								<div class="editRowMenu" onclick="editTableRow('{$tableId}','{$rowInd}');" onmouseover="this.className='editRowMenuHover'" onmouseout="this.className='editRowMenu'">Edit</div>
								<div class="editRowMenu" onclick="deleteTableRow('{$tableId}','{$rowInd}');" onmouseover="this.className='editRowMenuHover'" onmouseout="this.className='editRowMenu'">Delete</div>
							</td>
						</tr>
					</xsl:for-each>
				</tbody>
			</table>
		</div>
	</xsl:template>
</xsl:stylesheet>
